<?php
declare(strict_types=1);
namespace App\Products;
use App\Controller;
use Field\StoreProductConst;
use Field\StoreProductVerLogConst;

// hook controller_users_index_use.php

/**
 * @title   单页
 * @auth    true
 * @rank    10
 */
class Index extends Controller
{
    // hook controller_users_index_public_start.php

    // hook controller_users_index_public_end.php
    public int $CateID=4;
    /**
     * @title  产品列表
     * @rank    99
     */
    public function action_Index()
    {
        $rootCate = $this->SysCate->DataKey[$this->CateID];
        $cond=[
            StoreProductConst::CateID=>$this->CateID,
        ];
        $List = $this->StoreProduct->select($cond, [StoreProductConst::Rank => 1], 1, 100);
        return $this->View(get_defined_vars());
    }
    /**
     * @title  产品列表
     * @rank    99
     */
    public function action_Fuwu()
    {
       $this->CateID=5;
       return $this->action_Index();
    }

    /**
     * @title  产品详情
     * @rank    99
     */
    public function action_Detail()
    {
        $name = $this->request->param('name','');

        empty($name) && $this->response('0001',[],'产品不存在');
        $Product = $this->StoreProduct->read([StoreProductConst::Pinyin=>$name]);
        empty($Product[StoreProductConst::ProductID]) && $this->response('0001',[],'产品不存在');
        //获取内容页
        $ProductContent = $this->StoreProductContent->select([StoreProductConst::ProductID=>$Product[StoreProductConst::ProductID]]);
        $ProductContent = arrlist_sort_by_many_field($ProductContent,StoreProductConst::Rank,SORT_DESC);
        //获取功能
        $FuncList=[];
        $SimpleDescList=[];//简介
        $FuncImgList=[];//功能图
        $QaList=[];//功能图
        foreach ($ProductContent as $index => $item) {
            //全部功能
            if($item['TypeID']==3){
                $FuncList=array_merge($FuncList,explode("\n",$item['Content']));
                continue;
            }
            //功能亮点
            if($item['TypeID']==2){
                $SimpleDescList=array_merge($SimpleDescList,explode("\n",$item['Content']));
            }
            //功能亮点
            if($item['TypeID']==4){
                array_push($FuncImgList,'https://'._CONF('OssHost').$item['Content']);
            }
            if($item['TypeID']==5){
                $QaList[$item['Title']]=explode("\n",$item['Content']);
                continue;
            }
        }

        //获取更新日志
        $VersionContent = $this->StoreProductVerLog->select([StoreProductVerLogConst::ProductID=>$Product[StoreProductConst::ProductID]]);
        $VersionContent = arrlist_sort_by_many_field($VersionContent,StoreProductVerLogConst::CreateAt,SORT_DESC);
        return $this->View(get_defined_vars());

    }
    /**
     * @title  产品列表
     * @rank    99
     */
    public function action_Fuwudetail()
    {
        $this->CateID=5;
        return $this->action_Detail();
    }


    // hook controller_users_index_end.php
}
?>